<?php
class app_catalog extends app implements interface_app {

    public function pre_dispatch(){

        // Set URL
        $this->url->setURL($this->setting->get('http_server'));
        $this->url->setSSL($this->setting->get('https_server'));

        // Router
        if (isset($this->request->get['route'])) {
            $this->action = $this->action($this->request->get['route']);
        } 
         
        // Language Detection
        $local = new local($this->registry);
        $result = $local->get_language();

        $code = $result['code'];
        $language_id = $result['language_id'];
        $directory = $result['directory'];
        $filename =  $result['filename'];

        $language = $this->language($directory);
        $language->setCode($code);
        $language->setId($language_id);
        $language->load($filename);

        $this->setting->set('setting_language_id', $language->get_id());
        $this->setting->set('setting_language', $language->getCode());
        $this->registry->set('language',$language);

        // Theme
        $this->theme = $this->setting->get('config_template');

        // Affiliate
        $this->registry->set('affiliate', new Affiliate($this->registry));

        if (isset($this->request->get['tracking'])) {
            setcookie('tracking', $this->request->get['tracking'], time() + 3600 * 24 * 1000, '/');
        }

        // Currency
        $this->registry->set('currency', new Currency($this->registry));

        // Tax
        $this->registry->set('tax', new Tax($this->registry));

        // Weight
        $this->registry->set('weight', new Weight($this->registry));

        // Length
        $this->registry->set('length', new Length($this->registry));

        // Cart
        $this->registry->set('cart', new Cart($this->registry));

        $this->response->addHeader('Content-Type: text/html; charset=UTF-8');

   }
}
